package com.lqm.web.controller.home;

import com.lqm.entity.home.Project;
import com.lqm.entity.home.ProjectVo;
import com.lqm.entity.home.Slide;
import com.lqm.entity.home.SlideVo;
import com.lqm.service.home.ProjectSupportService;
import com.lqm.service.home.SlideService;
import com.lqm.util.ClassVoUtil;
import com.lqm.util.FormatProjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: CrowdFunding
 * @description
 * @author: lqm
 * @create: 2018-12-10 22:58
 */
@RestController
@RequestMapping("/home")
public class SlideController {

    @Autowired
    SlideService slideService;
    @Autowired
    ProjectSupportService projectSupportService;

    @RequestMapping("/getAllSlide")
    public Map<String, Object> getAllSlide() {
        HashMap<String, Object> map = new HashMap<>();

        List<Slide> allSlide = slideService.getAllSlide();
//        ArrayList<Object> objects = new ArrayList<>();
        ArrayList<SlideVo> slideVoArrayList = new ArrayList<>();
        for (Slide slide : allSlide) {


            Project project = FormatProjectUtil.formatProjectList(slide.getProject());


            SlideVo slideVo = ClassVoUtil.SlideVoCastSlideVoVo(slide);
            slideVo.setProject(null);


            //当前金额
            Double supportSumByProject = projectSupportService.findSupportSumByProject(project);

            ProjectVo projectVo = ClassVoUtil.ProjectCastProjectVo(project,supportSumByProject);

            slideVo.setProjectVo(projectVo);

            //过滤字段
            slideVo.getProjectVo().setDetail("");

            System.out.println(projectVo);
            slideVoArrayList.add(slideVo);

        }
//        System.out.println(objects);
        map.put("data",slideVoArrayList);
//        map.put("sss",objects);
        return map;
    }
}
